<template>
  <div class="wrap">
    <el-row>
      <!--工具条-->
      <el-col :span="24" class="header-wrap">
        <el-form :inline="true" :model="formInline" :rules="rules1" ref="formInline">
          <el-form-item label="记录时间">
            <el-date-picker
              v-model="date"
              type="datetimerange"
              range-separator="--"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              align="right">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="状态" prop="state">
            <el-select v-model="formInline.state" placeholder="请选择">
              <el-option label="全部" value=""></el-option>
              <el-option label="成功" value="0"></el-option>
              <el-option label="失败" value="1"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="search('formInline')">搜索</el-button>
          </el-form-item>
        </el-form>
      </el-col>
      <el-col :span="24">
        <el-table
          :data="feedbackList"
          :border="true"
          style="width: 100%;">
          <el-table-column prop="userName" label="管理员" align="center"></el-table-column>
          <el-table-column prop="content" label="操作内容" align="center"></el-table-column>

          <el-table-column prop="createtime" :formatter="dateFormat" label="操作时间" align="center"></el-table-column>
          <el-table-column label="状态" align="center">
            <template slot-scope="scope">
              <el-tag type="success" v-if="scope.row.state == 0">成功</el-tag>
              <el-tag type="danger" v-if="scope.row.state == 1">失败</el-tag>
            </template>
          </el-table-column>
        </el-table>
        <!--分页-->
        <el-pagination
          class="top"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-sizes="[10, 15, 20, 30]"
          :page-size="size"
          layout="total, sizes, prev, pager, next, jumper"
          :total='total'>
        </el-pagination>
      </el-col>
    </el-row>
    <!--处理-->
    <el-dialog :visible.sync="dialogFormVisible" width="20%" :close-on-click-modal="false">
      <div slot="title">处理</div>
      <el-form :model="form2">
        <el-form-item label="活动名称">
          <el-input v-model="form2.content" type="textarea" :rows="6" placeholder="请输反馈入内容"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="submit">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script type="text/ecmascript-6">
  import {post,fetch} from '@/utils/http'
  export default {
    data() {
      let validateName = (rule, value, callback) => {
        if (value === '') {
          callback();
        } else {
          callback();
        }
      };
      let validatePhone = (rule, value, callback) => {
        if (value == '') {
          callback();
        } else {
          callback();
        }
      };
      return {
        dialogFormVisible: false,
        formInline: {
          state: '',
        },
        form2: {
          content: ''
        },
        date: '',
        startTime: '',
        endTime: '',
        feedbackList: [],
        size: 10,
        currentPage: 1,
        total: 0,
        rules1: {
          name: [
            { validator: validateName, trigger: 'blur' }
          ],
          phone: [
            { validator: validatePhone, trigger: 'blur' },
          ]
        }
      }
    },
    methods: {
      dateFormat(row,column) {
        let tableTime = row[column.property];
        if (tableTime == undefined) {
          return "";
        }
        return this.moment(tableTime).format("YYYY-MM-DD HH:mm:ss");
      },
      getTime() {
        let starttime = '';
        let endtime = '';
        let time = this.date;
        if(!time[0] == '') {
          starttime = this.moment(time[0]).utc().format('YYYY-MM-DD[T]HH:mm:ss[Z]');
        }
        if(!time[1] == '') {
          endtime = this.moment(time[1]).utc().format('YYYY-MM-DD[T]HH:mm:ss[Z]');
        }
        if(starttime == "Invalid date"){
          starttime="";
        };
        if(endtime == "Invalid date"){
          endtime="";
        };
        this.startTime = starttime
        this.endTime = endtime
      },
      dispose(index, row) {
        this.dialogFormVisible = true
        console.log(row)
      },
      submit() {
        this.dialogFormVisible = false;
      },
      search(formInline) {
        this.getTime();
        this.$refs[formInline].validate((valid) => {
          if (valid) {
           let para = {
             pageIndex: this.currentPage,
             pageSize: this.size
           }
            if(!this.formInline.state == '') {
              para.state = this.formInline.state
            }
            if(!this.startTime == '') {
              para.startTime = this.startTime
            }
            if(!this.endTime == '') {
              para.endTime = this.endTime
            }
            post('/api/manager/v1/log/queryLog',para).then((response) => {
              this.feedbackList = response.data.data;
              this.total = response.data.totalCount;
              this.size = response.data.pageSize;
            }).catch((error) => {
              console.log(error)
            })
          }
        });
      },
      getList() {
        // 获取数据
        post('/api/manager/v1/log/queryLog',{pageIndex: this.currentPage,pageSize: this.size}).then((response) => {
          this.feedbackList = response.data.data;
          this.total = response.data.totalCount;
          this.size = response.data.pageSize;
        }).catch((error) => {
          console.log(error)
        })
      },
      handleSizeChange(val) {
        this.size = val;
        this.getList();
      },
      handleCurrentChange(val) {
        this.currentPage =val;
        this.getList();
      },
    },
    mounted(){
      this.getList();
    },
  }
</script>

<style lang='scss' scoped>
  .wrap {
    /*padding: 20px;*/
    .header-wrap{
      margin-bottom: 60px;
      background-color: #66BFBF;
      border-radius: 6px;
    }
    .el-form-item {
      margin-top: 22px;
      margin-left: 22px;
    }
    .top {
      margin-top: 10px;
      float: right;
    }
  }
</style>
